<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Message</title>

    <!-- Custom fonts for this template-->
    <link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
    <link
        href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i"
        rel="stylesheet">

    <!-- Custom styles for this template-->
    <link href="css/sb-admin-2.min.css" rel="stylesheet">

    <!-- Custom styles for this page -->
    <link href="vendor/datatables/dataTables.bootstrap4.min.css" rel="stylesheet">

</head>

<body id="page-top">

    <!-- Page Wrapper -->
    <div id="wrapper">

        <!-- Sidebar -->
        <!-- Sidebar -->
        <ul class="navbar-nav bg-gradient-primary sidebar sidebar-dark accordion" id="accordionSidebar">

            <!-- Sidebar - Brand -->
            <a class="sidebar-brand d-flex align-items-center justify-content-center">
                <div class="sidebar-brand-icon rotate-n-15">
                    <i class="fas fa-laugh-wink"></i>
                </div>
                <div class="sidebar-brand-text mx-3">买方员工</div>
            </a>

            <!-- Divider -->
            <hr class="sidebar-divider my-0">

            <!-- Nav Item - Dashboard -->
            <li class="nav-item">
                <a class="nav-link" id="Make">
                    <i class="fas fa-fw fa-wrench"></i>
                    <span>Make an Order</span></a>
            </li>

            <!-- Divider -->
            <hr class="sidebar-divider">

            <!-- Nav Item - Dashboard -->
            <li class="nav-item">
                <a class="nav-link" id="Draft">
                    <i class="fas fa-fw fa-table"></i>
                    <span>Draft Orders</span></a>
            </li>

            <!-- Divider -->
            <hr class="sidebar-divider">

            <!-- Nav Item - Dashboard -->
            <li class="nav-item">
                <a class="nav-link" id="History">
                    <i class="fas fa-fw fa-table"></i>
                    <span>Historical Orders</span></a>
            </li>

            <!-- Divider -->
            <hr class="sidebar-divider">

            <!-- Nav Item - Dashboard -->
            <li class="nav-item active">
                <a class="nav-link" id="Mess">
                    <i class="fas fa-fw fa-cog"></i>
                    <span>Message</span></a>
            </li>

            <!-- Divider -->
            <hr class="sidebar-divider d-none d-md-block">

            <!-- Sidebar Toggler (Sidebar) -->
            <div class="text-center d-none d-md-inline">
                <button class="rounded-circle border-0" id="sidebarToggle"></button>
            </div>

        </ul>
        <!-- End of Sidebar -->

        <!-- Content Wrapper -->
        <div id="content-wrapper" class="d-flex flex-column">

            <!-- Main Content -->
            <div id="content">

                <!-- Topbar -->
                <nav class="navbar navbar-expand navbar-light bg-white topbar mb-4 static-top shadow">

                    <!-- Sidebar Toggle (Topbar) -->
                    <button id="sidebarToggleTop" class="btn btn-link d-md-none rounded-circle mr-3">
                        <i class="fa fa-bars"></i>
                    </button>

                    <h4 class="m-0 font-weight-bold text-primary">Message</h4>

                    <!-- Topbar Navbar -->
                    <ul class="navbar-nav ml-auto">

                        <div class="topbar-divider d-none d-sm-block"></div>

                        <!-- Nav Item - User Information -->
                        <li class="nav-item dropdown no-arrow">
                            <a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button"
                                data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                <span class="mr-2 d-none d-lg-inline text-gray-600 small" id="name"></span>
                                <img class="img-profile rounded-circle"
                                    src="img/undraw_profile.svg">
                            </a>
                            <!-- Dropdown - User Information -->
                            <div class="dropdown-menu dropdown-menu-right shadow animated--grow-in"
                                aria-labelledby="userDropdown">
                                <a class="dropdown-item" id="settings">
                                    <i class="fas fa-cogs fa-sm fa-fw mr-2 text-gray-400"></i>
                                    Settings
                                </a>
                                <div class="dropdown-divider"></div>
                                <a class="dropdown-item" href="#" data-toggle="modal" data-target="#logoutModal">
                                    <i class="fas fa-sign-out-alt fa-sm fa-fw mr-2 text-gray-400"></i>
                                    Logout
                                </a>
                            </div>
                        </li>

                    </ul>

                </nav>
                <!-- End of Topbar -->
                <!-- /.container-fluid -->

            <!-- End of Main Content -->
        <!-- End of Content Wrapper -->

    </div>
    <!-- End of Page Wrapper -->

                    <!-- Begin Page Content -->
                    <div class="container-fluid">

    
                        <!-- DataTales Example -->
                        <div class="card shadow mb-4">
                            <div class="card-header py-3">
                                <h6 class="m-0 font-weight-bold text-primary">Purchase Plan</h6>
                            </div>
                            <div class="card-body">
                                <div class="table-responsive">
                                    <table class="table table-bordered" id="table" width="100%" cellspacing="0">
                                        <thead>
                                            <tr>
                                                <th>Order ID</th>
                                                <th>Seller ID</th>
                                                <th>Buyer ID</th>
                                                <th>List Status</th>
                                                <th>Bargain Number</th>
                                                <th>Total Price</th>
                                                <th>Order Time</th>
                                                <th>Update Time</th>
                                                <th>Opreation</th>
                                            </tr>
                                        </thead>
                                        <tfoot>
                                            <tr>
                                                <th>Order ID</th>
                                                <th>Seller ID</th>
                                                <th>Buyer ID</th>
                                                <th>List Status</th>
                                                <th>Bargain Number</th>
                                                <th>Total Price</th>
                                                <th>Order Time</th>
                                                <th>Update Time</th>
                                                <th>Opreation</th>
                                            </tr>
                                        </tfoot>
                                        <tbody id="tbody-user">
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
    
                    </div>
                    <!-- /.container-fluid -->  
                    
                    <!-- Modal -->
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title" id="myModalLabel">修改</h4>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <table style="border: 1;width: 450px;">
                                <tr>
                                <td style="width: 15%;"><span class="mr-2 d-none d-lg-inline text-gray-600 small">ID</span></td>
                                <td style="width: 85%;"><input type="text" class="form-control" id="uid" placeholder="ID"></td>
                                </tr>
                            </table>
                        </div>
                         
                        <div class="form-group">
                            <table style="border: 1;width: 450px;">
                                <tr>
                                <td style="width: 15%;"><span class="mr-2 d-none d-lg-inline text-gray-600 small">用户名</span></td>
                                <td style="width: 85%;"><input type="text" class="form-control" id="user_name" placeholder="用户名"></td>
                                </tr>
                            </table>    
                        </div>
                        <div class="form-group">
                            <table style="border: 1;width: 450px;">
                                <tr>
                                <td style="width: 15%;"><span class="mr-2 d-none d-lg-inline text-gray-600 small">机构ID</td>
                                <td style="width: 85%;"><input type="text" class="form-control" id="oid" placeholder="机构ID"></td>
                                </tr>
                            </table>    
                        </div>
                        <div class="form-group">
                            <table style="border: 1;width: 450px;">
                                <tr>
                                <td style="width: 15%;"><span class="mr-2 d-none d-lg-inline text-gray-600 small">用户权限</span></td>
                                <td style="width: 85%;"><input type="text" class="form-control" id="user_authority" placeholder="用户权限"></td>
                                </tr>
                            </table>    
                        </div>
                         
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary" id="save">保存</button>
                    </div>
                </div>
            </div>
        </div>

        <!-- Add Drug -->
        <!-- <div class="modal fade" id="Add-Drug" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title">Add Drugs</h4>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    </div>
                    <div class="modal-body">
                        <div class="card shadow mb-4">
                            <div class="card-body">
                                <div class="table-responsive">
                                    <table class="table table-bordered" id="add_drug" width="100%" cellspacing="0">
                                        <thead>
                                            <tr>
                                                <th>Enterprise Drug Code</th>
                                                <th>Drug Name</th>
                                                <th>Drug ID</th>
                                                <th>End Date</th>
                                                <th>Update Date</th>
                                                <th>Creation Date</th>
                                                <th>State of Drug</th>
                                                <th>Store Number</th>
                                                <th>Seller</th>
                                                <th>Unit Price</th>
                                                <th>Manufacturer</th>
                                                <th>Is Manufacturer Authorized</th>
                                                <th>Corresponding State</th>
                                                <th>Opreation</th>
                                            </tr>
                                        </thead>
                                        <tfoot>
                                            <tr>
                                                <th>Enterprise Drug Code</th>
                                                <th>Drug Name</th>
                                                <th>Drug ID</th>
                                                <th>End Date</th>
                                                <th>Update Date</th>
                                                <th>Creation Date</th>
                                                <th>State of Drug</th>
                                                <th>Store Number</th>
                                                <th>Seller</th>
                                                <th>Unit Price</th>
                                                <th>Manufacturer</th>
                                                <th>Is Manufacturer Authorized</th>
                                                <th>Corresponding State</th>
                                                <th>Opreation</th>
                                            </tr>
                                        </tfoot>
                                        <tbody>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-primary" id="save_add">确认添加</button>
                    </div>
                </div>
            </div>
        </div> -->

            <!-- Select Drug -->
            <div class="modal fade" id="Select-Drug" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog modal-lg">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4 class="modal-title">Edit List</h4>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                        </div>
                        <div class="modal-body">
                            <div class="card shadow mb-4">
                                <div class="card-body">
                                    <div class="table-responsive">
                                        <table class="table table-bordered" id="drug_table" width="100%" cellspacing="0">
                                            <thead>
                                                <tr>
                                                    <th>Order ID</th>
                                                    <th>Drug ID</th>
                                                    <th>Purchase Number</th>
                                                    <th>Unit Price</th>
                                                    <th>Discount</th>
                                                    <th>Guide Wholesale Price</th>
                                                    <th>Opinion</th>
                                                    <th>Drug Name</th>
                                                    <th>Edit Number&Discount</th>
                                                    <th>Delete</th>
                                                </tr>
                                            </thead>
                                            <tfoot>
                                                <tr>
                                                    <th>Order ID</th>
                                                    <th>Drug ID</th>
                                                    <th>Purchase Number</th>
                                                    <th>Unit Price</th>
                                                    <th>Discount</th>
                                                    <th>Guide Wholesale Price</th>
                                                    <th>Opinion</th>
                                                    <th>Drug Name</th>
                                                    <th>Edit Number&Discount</th>
                                                    <th>Delete</th>
                                                </tr>
                                            </tfoot>
                                            <tbody>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!-- <div class="modal-footer">
                            <button type="button" class="btn btn-primary" id="save_draft">存为草稿</button>
                        </div> -->
                    </div>
                </div>
            </div>
                    
                </div> 
    
    <!-- Scroll to Top Button-->
    <a class="scroll-to-top rounded" href="#page-top">
        <i class="fas fa-angle-up"></i>
    </a>

    <!-- Logout Modal-->
    <div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
        aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Ready to Leave?</h5>
                    <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                </div>
                <div class="modal-body">Select "Logout" below if you are ready to end your current session.</div>
                <div class="modal-footer">
                    <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
                    <a class="btn btn-primary" href="login.html">Logout</a>
                </div>
            </div>
        </div>
    </div>

    <!-- Bootstrap core JavaScript-->
    <script src="vendor/jquery/jquery.min.js"></script>
    <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

    <!-- Core plugin JavaScript-->
    <script src="vendor/jquery-easing/jquery.easing.min.js"></script>

    <!-- Custom scripts for all pages-->
    <script src="js/sb-admin-2.min.js"></script>

     <!-- Page level plugins -->
     <script src="vendor/datatables/jquery.dataTables.min.js"></script>
     <script src="vendor/datatables/dataTables.bootstrap4.min.js"></script>
 
     <!-- Page level custom scripts -->
     <script src="js/demo/datatables-demo.js"></script>
     <script src="plugin/handlebars-v3.0.1.js"></script>
      
<script id="tpl" type="text/x-handlebars-template">
        {{#each func}}
        <button type="button" class="btn btn-{{this.type}} btn-sm" onclick="{{this.fn}}">{{this.name}}</button>
        {{/each}}
</script>

<script>
    var table; //订单表
    var table_drug; //药品表
    $(document).ready(function (ev) {
        var tpl = $("#tpl").html();
        //预编译模板
        var template = Handlebars.compile(tpl);
        table=$('#table').DataTable(
        {
            "ajax":{
            "url":"http://210.30.97.103:20305/order/buyerQueryPurchasePlanHaveQuotedPrice", //前端->后端吧:user_name,后端->前端:被卖方打回的order
            "dataType":"json", 
            "type":"get",
            "data":{
                "username":document.getElementById("name").innerHTML
            },
            "dataSrc":function(result){
                return result;
            }
            },
            "columns":[
                {"data":"order_id"},
                {"data": "seller_oid"},
                {"data": "buyer_oid"},
                {"data": "list_status"},
                {"data": "bargain_num"},
                {"data": "total_prise"},
                {"data": "order_time"},
                {"data": "update_time"},
                {"data":null}
            ],
            "columnDefs": [
                {
                    targets: 8,
                    render: function (a, b, c, d) {
                        var context =
                        {
                            func: [
                                {"name": "Edit","fn": "edit_order(\'" + c.order_id + "\')", "type": "primary"},
                                {"name": "Delete","fn": "delete_order(\'" + c.order_id + "\')", "type": "danger"},
                                {"name": "Accept","fn": "accept_order(\'" + c.order_id + "\')", "type": "primary"},
                                {"name": "Refuse","fn": "refuse_order(\'" + c.order_id + "\')", "type": "primary"},
                            ]
                        };
                        // console.log(b.uid);
                        var html = template(context);
                        return html;
                    }
                }
 
            ],
            
         });
         $("#save").click(add);
});

function accept_order(order_id){//todo
    $.ajax({
        type: "put",
        url: "http://210.30.97.103:20305/order/buyerAgreePlan",//接受,前端->后端:order_id
        data: {
            "order_id": order_id
        }, success: function (xhr) {
            if(xhr.check==true){
                alert("成功");
            }
            else{
                alert("失败");
            }
            table.ajax.reload();
            console.log("接受");
        }
    });   
}

function refuse_order(order_id){
    $.ajax({
        type: "put",
        url: "http://210.30.97.103:20305/order/buyerDiscontinuePlan",//拒绝,前端->后端:order_id
        data: {
            "order_id": order_id
        }, success: function () {
            table.ajax.reload();
            console.log("拒绝");
        }
    });   
}

function edit_order(order_id){
    var tpl = $("#tpl").html();
        //预编译模板
    var template = Handlebars.compile(tpl);
    $("#drug_table").dataTable().fnDestroy();
    table_drug=$('#drug_table').DataTable(
    {
        "ajax":{
        "url":"http://210.30.97.103:20305/order/QueryPurchaseListByOrderID",//前端->后端:order_id,后端->前端,该订单的药品清单
        "dataType":"json",
        "type":"get",
        "data":{
            "order_id":order_id
        },
        "dataSrc":function(result){
            return result;
        }
        },
        "columns":[
            {"data": "order_id"},
            {"data": "drug_id"},
            {"data": "purchase_num"},
            {"data": "unit_price"},
            {"data": "discount"},
            {"data": "guide_wholesale_price"},
            {"data": "opinion"},
            {"data": "drug_name"},
            {"data": null},
            {"data": null}
        ],
        "columnDefs": [
            {
                targets: 8,
                render: function (a, b, c, d) {
                    return  "<input type=\"text\" class=\"form-control\" name=\"purchase_num\" placeholder=\"修改数量\" id="+c.drug_id+">"+
                    "<input type=\"text\" class=\"form-control\" name=\"discount\" placeholder=\"修改折扣\">"+
                    "<input type=\"text\" class=\"form-control\" name=\"opinion\" placeholder=\"意见\">"
                    //return "<input type=\"checkbox\" name=\"chec\" class=\"btn btn-{{this.type}} btn-sm\" value=" + c.enterprise_drug_code + ">";
                }
            },
            {
                targets: 9,
                render: function (data, type, row, meta) {
                    var context =
                        {
                            func: [
                            {"name": "Submit Change","fn": "submit_change(\'" + row.order_id  + "\',\'" + row.drug_id  + "\',\'" + meta.row  +  "\')", "type": "primary"},
                                {"name": "Delete Drug","fn": "delete_drug(\'" + row.order_id  + "\',\'"+ row.drug_id + "\')", "type": "danger"}
                            ]
                        };
                        // console.log(b.uid);
                        var html = template(context);
                        return html;
                }
            },
        ],

        // "dom": "<'row'<'col-md-3'l><'#mytool.col-md-3'><'col-md-6'f>r>"+
        //             "t" +
        //             "<'row'<'col-md-6'i><'col-md-6'p>>",
        //     "initComplete": function () {
        //         //$("#mytool").append('<button id="datainit" type="button" class="btn btn-primary btn-sm">增加基础数据</button>&nbsp');
        //         $("#mytool").append('<button type="button" class="btn btn-primary btn-sm" id="add_drug_btn">Add Drug</button>');
        //         $("#add_drug_btn").on("click", function(){
        //             console.log("???");
        //             $("#add_drug").dataTable().fnDestroy();
        //             var add;
        //             add=$('#add_drug').DataTable(
        //             {
        //                 "ajax":{
        //                 "url":"http://rap2api.tao bao.org/app/mock/281441/http://drug",
        //                 "dataType":"json",
        //                 "type":"get",
        //                 "data":{
        //                     "order_id":order_id
        //                 },
        //                 "dataSrc":function(result){
        //                     return result;
        //                 }
        //                 },
        //                 "columns":[
        //                     {"data": "enterprise_drug_code"},
        //                     {"data": "drug_name"},
        //                     {"data": "drug_id"},
        //                     {"data": "end_date"},
        //                     {"data": "update_date"},
        //                     {"data": "creation_date"},
        //                     {"data": "state_of_drug"},
        //                     {"data": "store_num"},
        //                     {"data": "oid_seller"},
        //                     {"data": "unit_price"},
        //                     {"data": "oid_manufacturer"},
        //                     {"data": "is_manufacturer_authorized"},
        //                     {"data": "corresponding_state"},
        //                     {"data": null}
        //                 ],
        //                 "columnDefs": [
        //                     {
        //                         targets: 13,
        //                         render: function (a, b, c, d) {
        //                             return  "<input type=\"text\" class=\"form-control\" name=\"purchase_num\" placeholder=\"购买数量\" id="+c.drug_id+">"+
        //                             "<input type=\"text\" class=\"form-control\" name=\"discount\" placeholder=\"折扣\">"
        //                             //return "<input type=\"checkbox\" name=\"chec\" class=\"btn btn-{{this.type}} btn-sm\" value=" + c.enterprise_drug_code + ">";
        //                         }
        //                     }

        //                 ],

        //                 });  
        //                 $("#Select-Drug").modal("hide");
        //                 $("#Select-Drug").on('hidden.bs.modal', function () {
        //                     document.getElementsByTagName('body')[0].className = 'modal-open';
        //                 });
        //                 $("#Add-Drug").modal("show");
        //                 $("#save_add").click(function(){
        //                 var C_ID = "[";
        //                 obj = document.getElementsByName("purchase_num");
        //                 obj2 = document.getElementsByName("discount");
        //                 for(k in obj) {
        //                     if(obj[k].value!=""&& obj[k].value!= undefined && obj[k].value!= null){
        //                         C_ID+="{\"drug_id\":"+obj[k].id+",\"purchase_num\":"+obj[k].value+",\"discount\":"+obj2[k].value+"},";
        //                     }

        //                 }
        //                 //list_status:0表示提交，1表示保存为草稿
        //                 C_ID+="{\"order_id\":"+order_id+"}";
        //                 C_ID+="]";
        //                 C_ID=JSON.parse(C_ID);
        //                 console.log(C_ID);
        //                 ajaxc(C_ID);
        //                 $("#Add-Drug").modal("hide");
        //                 }); 
        //                         });
        //                     }

                        });   
                        $("#Select-Drug").modal("show");
}

function submit_change(order_id,drug_id,row){
    // var tr = o.parentNode.parentNode;
    var C_ID="";
    obj = document.getElementsByName("purchase_num");
    obj2 = document.getElementsByName("discount");
    obj3 = document.getElementsByName("opinion");
    C_ID+="{\"order_id\":"+order_id+",\"drug_id\":"+drug_id+",\"purchase_num\":"+obj[row].value+",\"discount\":"+obj2[row].value+",\"opinion\":\""+obj3[row].value+"\"}";
    C_ID=JSON.parse(C_ID);
    console.log(C_ID);
    ajaxc(C_ID);
}

function ajaxc(C_ID) {
        console.log(C_ID);
        var url ="http://210.30.97.103:20305/order/editListAndLock" ;//前端->后端:修改的药品(单个):{"order_id":122,"drug_id":11,"purchase_num":9,"discount":0.9,"opinion":"vjv"}
        $.ajax({
            url:url,
            type:'put',
            dataType:"json",
            contentType: 'application/json;charset=utf-8',
            data: JSON.stringify(C_ID), 
            success: function (xhr) {
                $("#Select-Drug").modal("hide");
                console.log("success");
                if(xhr.check==false){
                    alert("输入的数量大于卖方库存数量，请检查。");
                }
            }
        });
    }

function delete_drug(order_id,drug_id) {
        $.ajax({
            type: "delete",
            url: "http://210.30.97.103:20305/order/deleteList",//删除订单里的药品,前->后:order_id,drug_id
            data: {
                "order_id":order_id,
                "drug_id": drug_id
            }, success: function () {
                table_drug.ajax.reload();
                console.log("删除成功");
            }
        });
    }

function delete_order(order_id) {
    $.ajax({
        type: "delete",
        url: "http://210.30.97.103:20305/order/deletePlanAndLists",//前端->后:order_id 删除订单(终止)
        data: {
            "order_id": order_id
        }, success: function () {
            table.ajax.reload();
            console.log("删除成功");
        }
    });
}

function add() {
        var addJson = {
            "uid": $("#uid").val(),
            "role_name": $("#role_name").val(),
            "user_name": $("#user_name").val(),
            "password": $("#password").val(),
            "question": $("#question").val(),
            "answer": $("#answer").val(),
            "oid": $("#oid").val(),
            "seller_info": $("#seller_info").val(),
            "buyer_info": $("#buyer_info").val(),
            "user_state": $("#user_state").val(),
            "user_authority": $("#user_authority").val(),
        };
        // console.log(addJson);
        ajax(addJson);
    }

    function edit(uid,role_name,user_name,password,question,answer,oid,seller_info,buyer_info,user_state,user_authority,salt,is_organization_accept) {
        const authority=["什么都不是","临时机构","卖方系统管理员","买方系统管理员","厂商系统管理员","运营商系统管理员","药品全档管理员","卖方业务员","卖方开票员","买方业务员"];ity=["什么都不是","临时机构","卖方系统管理员","买方系统管理员","厂商系统管理员","运营商系统管理员","药品全档管理员","卖方业务员","卖方开票员","买方业务员"];
        // console.log(uid);
        $("#uid").val(uid).attr("disabled",true);
        $("#role_name").val(role_name);
        $("#user_name").val(user_name).attr("disabled",true);
        $("#password").val(password);
        $("#question").val(question);
        $("#answer").val(answer);
        $("#oid").val(oid).attr("disabled",true);
        $("#seller_info").val(seller_info);
        $("#buyer_info").val(buyer_info);
        $("#user_state").val(user_state);
        $("#user_authority").val(authority[user_authority]).attr("disabled",true);
        $("#myModal").modal("show");
    }

    function ajax(obj) {//用来修改用户信息
        var url ="http://210.30.97.103:20305/admin/users";
        var data={
                "uid": obj.uid,
                "role_name": obj.role_name,
                "user_name": obj.user_name,
                "password": obj.password,
                "question": obj.question,
                "answer": obj.answer,
                "oid": obj.oid,
                "seller_info": obj.seller_info,
                "buyer_info": obj.buyer_info,
                "user_state": obj.user_state,
                "user_authority": obj.user_authority,
                "salt": obj.salt,
                "is_organization_accept": obj.is_organization_accept
            };
        $.ajax({// 参照!
            "url":url,
            "type":"put",
            contentType: 'application/json;charset=utf-8',
            data: JSON.stringify(data),
            dataType:'json',
             success: function () {
                table.ajax.reload();
                $("#myModal").modal("hide");
                console.log(obj);
                alert("修改成功!")
            }
        });
    }
</script>

<script type="text/javascript">
    var url=decodeURI(location.href);
    var num=url.indexOf("?");
    var str=url.substr(num+1);
    $("#name").html(""+str);
</script>

<script src="js/myAjax.js"></script>
<script>
    $("#settings").click(function(ev){
        myajax({
                    type:"get",
                    url:"http://210.30.97.103:20305/seller/getUserInfoByUserName",//DONE:查看管理员的信息完成
                    data:{
                        "username":document.getElementById('name').innerHTML
                    },
                    success: function (xhr) {
                        // console.log(xhr.responseText);
                        var result = xhr.responseText;
                        /*
                        在低版本的IE中, 不可以使用原生的JSON.parse方法, 但是可以使用json2.js这个框架来兼容
                        */
                        var obj = JSON.parse(result);
                        edit(obj.uid,obj.role_name,obj.user_name,obj.password,obj.question,obj.answer,obj.oid,obj.seller_info,obj.buyer_info,obj.user_state,obj.user_authority,obj.salt,obj.is_organization_accept);
                    },
                    error: function (xhr) {
                        alert(xhr.status);
                        
                    }
                });
    })
</script>

<script>
    $("#Make").click(function(ev){
        console.log($("#name").val());
        window.location.href="buyer_operator.html?"+document.getElementById('name').innerHTML+"";
    })
</script>

<script>
    $("#Draft").click(function(ev){
        console.log($("#name").val());
        window.location.href="buyer_draft.html?"+document.getElementById('name').innerHTML+"";
    })
</script>

<script>
    $("#History").click(function(ev){
        console.log($("#name").val());
        window.location.href="order_manager.html?"+document.getElementById('name').innerHTML+"";
    })
</script>

<script>
    $("#Mess").click(function(ev){
        console.log($("#name").val());
        window.location.href="message.html?"+document.getElementById('name').innerHTML+"";
    })
</script>

</body>
</html>